package saucaca.Adapter;

import java.util.ArrayList;
import java.util.List;

import saucaca.Object.AlbumObject;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lemon.kenhnhacvn.BaseActivity;
import com.lemon.kenhnhacvn.R;

public class AlbumAdapterGridview extends ArrayAdapter<AlbumObject> {
	Context context;
	List<AlbumObject> data = new ArrayList<AlbumObject>();
	ImageLoader imageLoader;
	public AlbumAdapterGridview(Context context, List<AlbumObject> data) {
		super(context, R.layout.item_album_gridview, data);
		this.context = context;
		this.data = data;
		imageLoader=((BaseActivity)context).imageLoader;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		RecordHolder holder = null;
		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(R.layout.item_album_gridview, parent, false);
			holder = new RecordHolder();
			holder.txtTitle = (TextView) row.findViewById(R.id.custom_view_album_Title);
			holder.txtArtist = (TextView) row.findViewById(R.id.custom_view_album_artist);
			holder.imageItem = (ImageView) row.findViewById(R.id.custom_view_album_image);
			row.setTag(holder);
		} else {
			holder = (RecordHolder) row.getTag();
		}
		AlbumObject item = data.get(position);
		holder.txtTitle.setText(item.getTXNAME());
		holder.txtArtist.setText(item.getSEO_NAME());
		imageLoader.get(item.getAVATAR(),ImageLoader.getImageListener(holder.imageItem,
			         R.drawable.ic_default, R.drawable.ic_default));
		
		return row;
	}

	static class RecordHolder {
		TextView txtTitle;
		TextView txtArtist;
		ImageView imageItem;
	}
}
